package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;

class zadz {
   private zafg a = null;
   private Workbook b = null;
   private Worksheet c = null;
   private double d;
   private int e;
   private zaeh f = null;
   private zaem g = null;
   private boolean h = true;
   private HtmlSaveOptions i;
   private String j;
   private int[] k;
   private String l = null;
   private int m = 0;

   public void a(String var1) {
      this.j = var1;
   }

   zadz(zaeh var1, Worksheet var2, zafg var3, String var4, String var5, String var6, String var7, HtmlSaveOptions var8) throws Exception {
      this.i = var8;
      this.f = var1;
      this.j = var5;
      this.c = var2;
      this.a = var3;
      this.g = new zaem(this.f, var2, var3, var4, this.j, var6, var7, var8);
      this.b = this.f.g;
      this.d = this.c.getCells().getStandardHeight();
      this.e = this.c.getCells().getStandardWidthPixels();
      ColumnCollection var9 = var2.getCells().getColumns();

      for(int var10 = this.g.b(); var10 > -1; --var10) {
         if (var9.get(var10).c() > -1 && var9.get(var10).c() != 15) {
            Column var11 = var9.get(var10);
            this.k = new int[var11.getIndex() + 1];
            this.k[var11.getIndex()] = var11.c();
            --var10;

            for(; var10 > -1; --var10) {
               var11 = var9.get(var10);
               if (var11.c() < 0) {
                  this.k[var11.getIndex()] = 15;
               } else {
                  this.k[var11.getIndex()] = var11.c();
               }
            }
         }
      }

      if (this.k == null) {
         this.k = new int[0];
      }

   }

   void a() throws Exception {
      this.e();
      this.d();
      this.b();
      this.a.b("</table>");
   }

   private void b() throws Exception {
      Cells var1 = this.c.getCells();
      int var2 = -1;
      int var3 = var1.getRows().getCount();

      for(int var4 = 0; var4 < var3; ++var4) {
         this.b.l();
         Row var5 = var1.getRows().getRowByIndex(var4);
         int var6 = var5.getIndex();
         if (var6 > var2 + 1) {
            this.a(var2, var6);
         }

         this.a(var5);
         var2 = var6;
      }

      if (var2 < this.g.c()) {
         this.a(var2, this.g.c() + 1);
      }

      if (this.i.getExportBogusRowData()) {
         this.c();
      }

   }

   private void a(int var1, int var2) throws Exception {
      zaej var3 = null;

      for(int var4 = var1 + 1; var4 < var2; ++var4) {
         zaej var5 = this.g.a((Row)null, var4);
         var5.a(this.j);
         if (this.a(var3, var5)) {
            var3.a(var3.b() + 1);
         } else {
            if (var3 != null) {
               this.a(var3);
            }

            var3 = var5;
         }
      }

      if (var3 != null) {
         this.a(var3);
      }

   }

   private boolean a(zaej var1, zaej var2) {
      if (var1 != null && var2 != null) {
         return var1.c() == null && var1.g() && var2.c() == null && var2.g();
      } else {
         return false;
      }
   }

   private void c() throws Exception {
      this.a.b("<![if supportMisalignedColumns]>");
      this.a.b(" <tr height=0 style='display:none'>");

      for(int var1 = 0; var1 <= this.g.b(); ++var1) {
         int var2 = this.g.a(var1);
         double var3 = this.f.d().a(var2);
         if (this.i.getHiddenColDisplayType() != 1 || var2 != 0 && var3 != 0.0D) {
            StringBuilder var5 = new StringBuilder();
            var5.append("  <td width=").append(zase.y(var2)).append(" style='width:").append(zase.b(var3)).append("pt'></td>");
            this.a.b(com.aspose.cells.b.a.zr.a(var5));
         }
      }

      this.a.b(" </tr>");
      this.a.b(" <![endif]>");
   }

   private void a(Row var1) throws Exception {
      zaej var2 = this.g.a(var1, var1.getIndex());
      int var3 = 0;
      int var4 = var1.d();
      if (var4 < 0) {
         var4 = 15;
      }

      int var5 = var1.a();
      if (var5 > this.g.b() + 1) {
         var5 = this.g.b() + 1;
      }

      for(int var6 = 0; var6 < var5; ++var6) {
         Cell var7 = var1.getCellByIndex(var6);
         if (var3 <= var7.getColumn() && var7.getColumn() <= this.g.b() + 1) {
            if (var3 < var7.getColumn() && var4 == 15 && var3 < this.k.length) {
               for(int var8 = Math.min(var7.getColumn(), this.k.length); var3 < var8; ++var3) {
                  if (this.k[var3] != 15) {
                     var2.a(var1.getIndex(), var3, this.k[var3]);
                  }
               }
            }

            var2.a(var7);
            var3 = var7.getColumn() + 1;
         }
      }

      if (var3 < this.k.length) {
         for(; var3 < this.k.length; ++var3) {
            if (this.k[var3] != 15) {
               var2.a(var1.getIndex(), var3, this.k[var3]);
            }
         }
      }

      var2.a(var1.getIndex(), this.g.b());
      this.a(var2);
   }

   private void a(zaej var1) throws Exception {
      if (this.h) {
         var1.e = true;
         this.h = false;
      }

      boolean var2 = this.b(var1);
      if (!var2) {
         ArrayList var3 = var1.f();
         HashMap var4 = new HashMap();
         if (var1.a() != null) {
            for(int var5 = 0; var5 < var1.a().size(); ++var5) {
               zaen var6 = (zaen)var1.a().get(var5);
               if (var6.d > 1) {
                  for(int var7 = var1.d(); var7 < var1.d() + var6.d; ++var7) {
                     if (!var1.c().c.get(var7).isHidden()) {
                        var4.put(var5, var6.d);
                        break;
                     }
                  }
               }
            }
         }

         ArrayList var11;
         if (var4.size() > 0 && this.l != null) {
            var11 = (ArrayList)this.f.f.get(this.c.m());
            if (var11 == null) {
               var11 = new ArrayList();
               com.aspose.cells.b.a.a.ze.a(var11, (Object)this.l);
               this.f.f.put(this.c.m(), var11);
            } else {
               com.aspose.cells.b.a.a.ze.a(var11, (Object)this.l);
            }
         }

         var11 = null;

         for(int var12 = 0; var12 < var3.size(); ++var12) {
            String var13 = (String)var3.get(var12);
            if (var4.size() > 0) {
               String var14 = "tdr0";
               if (var4.get(var12) == null) {
                  if (var1.c().c.get(var1.d()).isHidden()) {
                     ArrayList var15 = (ArrayList)this.f.b.get(this.c.m());
                     if (var15 == null) {
                        var15 = new ArrayList();
                        com.aspose.cells.b.a.a.ze.a(var15, (Object)"t0");
                        this.f.b.put(this.c.m(), var15);
                        var14 = "id='t0'";
                     } else {
                        var14 = "id='t" + var15.size() + "'";
                        com.aspose.cells.b.a.a.ze.a(var15, (Object)("t" + var15.size()));
                     }

                     var13 = "<td " + var14 + var13.substring(3, 3 + (var13.length() - 3));
                  }
               } else {
                  int var8 = (Integer)var4.get(var12);
                  int var9 = 0;

                  for(int var10 = var1.d() + 1; var10 < var1.d() + var8; ++var10) {
                     if (var1.c().c.get(var10).isHidden()) {
                        ++var9;
                     }
                  }

                  if (var9 != 0) {
                     var8 -= var9;
                     HashMap var16 = (HashMap)this.f.e.get(this.c.m());
                     if (var16 == null) {
                        var16 = new HashMap();
                        var16.put("tdr0", var8);
                        this.f.e.put(this.c.m(), var16);
                        var14 = "id='tdr0'";
                     } else {
                        var14 = "id='tdr" + var16.size() + "'";
                        var16.put("tdr" + var16.size(), var8);
                     }

                     var13 = "<td " + var14 + var13.substring(3, 3 + (var13.length() - 3));
                  }
               }
            }

            this.a.b(var13);
         }

         this.a.b(" </tr>");
         this.l = null;
      }
   }

   private boolean b(zaej var1) throws Exception {
      double var2 = var1.i();
      StringBuilder var4 = new StringBuilder(100);
      StringBuilder var5 = new StringBuilder(100);
      if (var2 > 1.0E-7D) {
         var4.append(" <tr height=");
         var5.append(" style='mso-height-source:userset;height:");
         var4.append(this.f.d().a(var2));
         var5.append(zase.b(var2)).append("pt");
      } else {
         if (this.i.getHiddenRowDisplayType() == 1) {
            return true;
         }

         var4.append(" <tr height=0");
         var5.append(" style='display:none");
      }

      if (var1.b() > 1) {
         var5.append(";mso-xlrowspan:").append(zase.y(var1.b()));
      }

      Row var6 = var1.c();
      if (var6 != null && var6.d() != -1 && var6.d() != 15) {
         var4.append(" class=x").append(zase.y(var6.d()));
      }

      var4.append(com.aspose.cells.b.a.zr.a(var5));
      var4.append("'");
      this.l = "r" + this.m;
      ++this.m;
      var4.append(" id='" + this.l);
      var4.append("'>");
      this.a.b(com.aspose.cells.b.a.zr.a(var4));
      return false;
   }

   private void d() throws Exception {
      ArrayList var1 = this.g.d();

      for(int var2 = 0; var2 < var1.size(); ++var2) {
         zaeg var3 = (zaeg)var1.get(var2);
         this.a(var3);
      }

   }

   private void a(zaeg var1) throws Exception {
      StringBuilder var2 = new StringBuilder(100);
      if (var1.g) {
         var2.append(" <col");
         var2.append(" width=").append(zase.y(this.e));
         if (var1.b > 1) {
            var2.append(" span=").append(zase.y(var1.b));
         }

         if (this.i.getPresentationPreference()) {
            var2.append(" style='width:").append(zase.y(this.e)).append("px'>");
         } else {
            var2.append(" style='width:").append(zase.b(this.f.d().a(this.e))).append("pt'>");
         }
      } else {
         int var3;
         if (var1.d) {
            var3 = var1.e;
            var2.append(" <col");
            if (var3 != 15) {
               var2.append(" class=x").append(zase.y(var3));
            }

            var2.append(" width=0");
            var2.append(" mso-width=0");
            if (var1.b > 1) {
               var2.append(" span=").append(zase.y(var1.b));
            }

            if (this.i.getHiddenColDisplayType() == 1) {
               return;
            }

            ArrayList var4 = (ArrayList)this.f.b.get(this.c.m());
            if (var4 == null) {
               var4 = new ArrayList();
               com.aspose.cells.b.a.a.ze.a(var4, (Object)"c0");
               this.f.b.put(this.c.m(), var4);
               var2.append(" id='c0'");
            } else {
               var2.append(" id='c");
               var2.append(var4.size());
               var2.append("'");
               com.aspose.cells.b.a.a.ze.a(var4, (Object)("c" + var4.size()));
            }

            var2.append(" style='mso-width-source:userset;width:0pt;mso-width-alt:0pt'>");
         } else {
            var3 = var1.e;
            var2.append(" <col");
            if (var3 != 15) {
               var2.append(" class=x").append(zase.y(var3));
            }

            var2.append(" width=").append(zase.y(var1.c));
            if (var1.b > 1) {
               var2.append(" span=").append(zase.y(var1.b));
            }

            if (this.i.getPresentationPreference()) {
               var2.append(" style='mso-width-source:userset;width:").append(zase.y(var1.c)).append("px'>");
            } else {
               var2.append(" style='mso-width-source:userset;width:").append(zase.b(this.f.d().a(var1.c))).append("pt'>");
            }
         }
      }

      this.a.b(com.aspose.cells.b.a.zr.a(var2));
   }

   private void e() throws Exception {
      long var1 = this.g.e();
      long var3 = var1 * 3L / 4L;
      String var5 = "<table border=0 cellpadding=0 cellspacing=0 width=" + zase.a(var1) + " style='border-collapse: ";
      this.a.b(com.aspose.cells.b.a.zr.a(var5));
      var5 = " collapse;table-layout:fixed;width:" + zase.a(var3) + "pt'>";
      this.a.b(com.aspose.cells.b.a.zr.a(var5));
   }
}
